package com.yidu.Controller;

import com.yidu.model.BokeUser;
import com.yidu.service.UserService;
import com.yidu.utils.BaseMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>@Description: 用户功能控制器</p>
 * <p>@author yidu-yuxigan</p>
 * <p>@Date:2021/1/17</p>
 * <p>@Time:13:44</p>
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService service;

    @RequestMapping("/login")
    @ResponseBody
    public BaseMessage login(BokeUser user, HttpServletRequest request){
        BokeUser bokeUser=service.login(user);
        HttpSession session = request.getSession();
        session.setAttribute("user",bokeUser);
        return bokeUser!=null?BaseMessage.succes(bokeUser):BaseMessage.fos();
    }
}
